public class Test {

    public static void main(String[] args) {
        //迭代思路
        int N = 5;
        int a = 1;
        int b = 1;
        int c = 1;
        while(N>2) {
           c = a+b;
           a = b;
           b = c;
           N--;
        }
        System.out.println(c);
    }
    public static void main5(String[] args) {
        //斐波拉契
        int N = 5;
        int sum = fib(N);
        System.out.println(sum);
    }
    public static int fib(int n) {
        if(n<=2) {
            return 1;
        }
        return fib(n-2)+fib(n-1);
    }
    public static void main4(String[] args) {
        //求数字的每一位之和
        int N = 1234;
        int sum = sumEvery(N);
        System.out.println(sum);
    }
    public static int sumEvery(int n) {
        if(n==1) {
            return n;
        }
        return n%10+sumEvery(n/10);
    }
    public static void main3(String[] args) {
        //顺序打印数组的每一位
        int num = 1234;
        print(num);
    }
    public static void print(int n) {
        if(n<10) {
            System.out.print(n+" ");
            return;
        }
        print(n/10);
        System.out.print(n%10+" ");

    }
    public static void main2(String[] args) {
        //递归求和
        int N = 3;
        int sum = sum(N);
        System.out.println(sum);
    }
    public static int sum(int n) {
        if(n==1) {
            return 1;
        }
        return n+sum(n-1);
    }

    public static void main1(String[] args) {
        //递归求N的阶乘

        int N = 6;
        int sum = sub(N);
        System.out.println(sum);
    }
    public static int sub(int n) {
        if(n==1) {
            return 1;
        }
        return n * sub(n-1);
    }


}
